<!-- Content Wrapper. Contains page content -->
<!--<meta http-equiv="refresh" content="10">-->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      工单详情
      <small></small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
      <li class="active">Here</li>
    </ol>
  </section>
  <!-- Main content -->
  <section class="content">

    <div class="row">
      <div class="col-xs-12">

        <div class="box">
          <div class="box-body">
            <table id="data_table" class="table table-bordered table-striped">
              <thead>
              <tr>
                <th>工单编号</th>
                <th>数据库名称</th>
                <th>状态</th>
                <th>执行时间</th>
                <% if audited_script.code_audit? %>
                    <th>校验进度</th>
                <% end %>
                <% if audited_script.execute_plan? %>
                    <th>进度(已执行/失败数/总数)</th>
                <% end %>
                <th>耗时</th>
                <% if current_user.can_audited? && audited_script.can_audited? %>
                    <th>审核</th>
                <% end %>
                <% if current_user.can_cancel? && audited_script.can_execute_now? %>
                    <th>立即执行</th>
                <% end %>
                <% if current_user.can_cancel? && audited_script.can_cancel? %>
                    <th>取消</th>
                <% end %>
                <th>报告</th>
              </tr>
              </thead>
              <tbody>
              <% @sql_order_detail.each do |sql_order_history| %>
                  <tr>
                    <td><%= sql_order_history.id %></td>
                    <td><%= sql_order_history.database.dbname %>-<%= sql_order_history.database.env %></td>
                    <td><%=  I18n.t(sql_order_history.status) %></td>
                    <td><%= sql_order_history.exec_time.try(:strftime,'%Y-%m-%d %H:%M:%S') %></td>
                    <% if audited_script.code_audit? %>
                        <td><%= sql_order_history.done_entries %>/<%= sql_order_history.all_entries %></td>
                    <% end %>
                    <% if audited_script.execute_plan? %>
                        <td><%= sql_order_history.done_entries %>/<%= sql_order_history.error_entries %>/<%= sql_order_history.all_entries %></td>
                    <% end %>
                    <% if sql_order_history.fin_time== nil %>
                        <td> </td>
                    <%end%>
                    <% if sql_order_history.fin_time != nil %>
                        <td><%= "%5.3f" % (sql_order_history.fin_time - sql_order_history.exec_time).to_f rescue nil %> 秒</td>
                    <%end%>
                    <% if current_user.can_audited?  && audited_script.can_audited? %>
                        <td>
                          <div class="btn-group">
                            <button type="button" class="btn btn-info table_btn" onclick=location.href="/sql_history/auditor_succeed/<%= sql_order_history.id %>">通过</button>
                            <button type="button" class="btn btn-info table_btn" onclick=location.href="/sql_history/auditor_fail/<%= sql_order_history.id %>">驳回</button>
                          </div>
                        </td>
                    <% end %>
                    <% if current_user.can_cancel? && audited_script.can_execute_now? %>
                        <td>
                          <div class="btn-group">
                            <button type="button" class="btn btn-info table_btn" onclick=location.href="/sql_history/execute_now/<%= sql_order_history.id %>">立即执行</button>
                          </div>
                        </td>
                    <% end %>
                    <% if current_user.can_cancel? && audited_script.can_cancel? %>
                        <td>
                          <div class="btn-group">
                            <button type="button" class="btn btn-info table_btn" onclick=location.href="/sql_history/cancel/<%= sql_order_history.id %>">取消</button>
                          </div>
                        </td>
                    <% end %>
                    <td>
                      <div class="btn-group">
                        <button type="button" class="btn btn-info table_btn" onclick="window.open('/sql_history/report/<%= sql_order_history.sql_content.id %>')">报告</button>
                      </div>
                    </td>
                  </tr>
              <% end %>
              </tbody>
            </table>
          </div>
          <!-- /.box-body -->
        </div>
        <!-- /.box -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </section>
  <!-- /.content -->
</div><!-- /.content-wrapper -->

<script type="text/javascript">
  $(function () {
    //列表排序脚本
    $("#data_table").dataTable({
      "bSort": false
    });
  })
</script>
